package ui.activity.mine.presenter;


import com.google.gson.Gson;

import javax.inject.Inject;

import base.BaseBiz;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import ui.activity.mine.PhoneAct;
import ui.activity.mine.biz.ChangePhoneBiz;
import ui.activity.mine.contract.ChangePhoneContract;
import ui.model.AuthBean;
import util.StringUtils;

/**
 * Created by chenjian on 19/2/26
 */

public class ChangePhonePresenter implements ChangePhoneContract.Presenter {

    ChangePhoneContract.View view;
    ChangePhoneBiz changePwdBiz;


    @Inject
    public ChangePhonePresenter(ChangePhoneContract.View view) {
        this.view = view;
    }


    @Override
    public void setBiz(BaseBiz biz) {
        changePwdBiz = (ChangePhoneBiz) biz;
    }


    @Override
    public void setPwd(boolean isShow) {
        view.upDatePwd(isShow);
    }

    @Override
    public void submitPwd(String pwd) {
        if (StringUtils.isEmpty(pwd)) {
            view.showMsg("请输入密码");
            return;
        }
        AuthBean p = new AuthBean();
        p.setPassword(pwd);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(p));
        changePwdBiz.setPwd(requestBody, new BaseBiz.Callback<Boolean>() {
            @Override
            public void onSuccess(Boolean info) {
                view.startAct(PhoneAct.class, null);
                view.loading(false);
            }

            @Override
            public void onFailure(Boolean info) {
                view.loading(false);
            }
        });
    }
}
